
const save = function () {
  let data = arguments[0]
  let fn   = arguments[1]

  return new Promise((fn, reject) => {
    // 保存数据
    if (typeof data.val != "string") {
      localStorage.setItem(data.key, JSON.stringify(data.val))
    } else {
      localStorage.setItem(data.key, data.val)
    }
    // 如果回调函数存在就执行
    fn ()
  })
}


const get = function (key, json) {
  return new Promise((resolve, reject)  => {
   let res = localStorage.getItem(key)
    if (res) {
      if(json) {
        resolve(JSON.parse(res))
      } else {
        resolve(res)
      }

    }
  })
}


export default {
  save,
  get
}
